<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="author" content="">
<title></title>
<!--    <link href="assets/css/icons.css" rel="stylesheet"> -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/style.css" rel="stylesheet">
<!--     <link href="assets/css/responsive.css" rel="stylesheet"> -->

</head>

<body>
	培训页面


	<h2 class="header-title text-center" id="title">添加员工信息</h2>
	<form id="params">
		<table class="table">
			<tr>
				<td>部门名称：</td>
				<td><select id="departName" name="departName"></select></td>
				<td>姓名：</td>
				<td><input id="empName" name="empName"></td>
			</tr>
			<tr>
				<td>年龄：</td>
				<td><input id="empAge" name="empAge"></td>
				<td>性别：</td>
				<td>
					<select id="sex" name="sex">
						<option>男</option>
						<option>女</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>出生日期：</td>
				<td><input id="empBirthday" name="empBirthday"
					readonly="readonly"></td>
				<td>身份证号：</td>
				<td><input id="empID" name="empID"></td>
			</tr>
			<tr>
				<td>民族：</td>
				<td><input id="nation" name="nation"></td>
				<td>婚姻状况：</td>
				<td>
					<select id="marryStatus" name="marryStatus">
						<option>未婚</option>
						<option>已婚</option>
						<option>离异</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>政治面貌：</td>
				<td>
					<select id="politicalStatus" name="politicalStatus">
						<option>党员</option>
						<option>团员</option>
						<option>无党派</option>
					</select>
				</td>
				<td>籍贯：</td>
				<td><input id="birthAddr" name="birthAddr"></td>
			</tr>
			<tr>
				<td>联系电话：</td>
				<td><input id="phone" name="phone"></td>
				<td>家庭住址：</td>
				<td><input id="homeAddr" name="homeAddr"></td>
			</tr>
			<tr>
				<td>毕业学校：</td>
				<td><input id="school" name="school"></td>
				<td>专业：</td>
				<td><input id="professional" name="professional"></td>
			</tr>
			<tr>
				<td>文化程度：</td>
				<td>
					<select id="education" name="education">
						<option>小学及以下</option>
						<option>中学</option>
						<option>大学</option>
						<option>研究生</option>
					</select>
				</td>
				<td>上岗时间：</td>
				<td><input id="joinTime" name="joinTime" readonly="readonly"></td>
			</tr>
			<tr>
				<td>登记人名：</td>
				<td><input id="signName" name="signName"></td>
				<td>登记时间：</td>
				<td><input id="signTime" name="signTime" readonly="readonly"></td>
			</tr>
			<tr>
				<td>部门工种：</td>
				<td>
					<select id="jobType" name="jobType">
						<option>测试</option>
						<option>开发</option>
						<option>产品</option>
						<option>其他</option>
					</select>
				</td>
				<td>备注信息：</td>
				<td><input id="remark" name="remark"></td>
			</tr>
		</table>
	</form>
	<div class="form-group">
		<input type="button" id="confirmDept" value="确定"
			class="btn btn-primary btn-block"> <input type="button"
			id="returnDept" value="返回" class="btn btn-primary btn-block">
	</div>
	<script>
		$(function() {
			//加载数据
			initData();
			
			//日期插件
			laydate.render({
				elem : '#empBirthday' //指定元素
			});
			laydate.render({
				elem : '#joinTime'
			});
			laydate.render({
				elem : '#signTime'
			});
			//数据校验
			checkData();
			
			//标题
// 			$("#title").html("修改员工信息");
			//截取参数
			var id = deptId;
			if (id != null) {

				$.ajax({
					type : "get",
					url : "/HMS/queryEmpInfoById",
					dataType : 'json',
					data : {
						"id" : id
					},
					contentType : "application/json;charset=UTF-8",
					success : function(obj) {
						$("#deptName").val(obj.Obj.data[0].departmentName);
						$("#deptTime").val(
								new Date(obj.Obj.data[0].createTime)
										.toLocaleString());
						$("#deptNum").val(obj.Obj.data[0].personNum);
						$("#remark").val(obj.Obj.data[0].remark);
					},
					error : function(data) {
						alert('连接失败');
					}
				});
			}

			//确认按钮
			$("#confirmDept").click(function() {
				var params = $("#params").serialize();
				//添加新的员工
				$.ajax({
					type : "get",
					url : "/HMS/addEmpInfo?" + params,
					dataType : 'json',
					contentType : "application/json;charset=UTF-8",
					success : function(value) {
						if (value.success == "OK") {
							// 							addTable();
							alert("操作成功");

						} else {
							//登陆失败
							alert("操作失败")
						}
					},
					error : function(data) {
						alert('连接失败');
					}
				});
			});
			//返回按钮
			$("#returnDept").click(function() {
				initEmp();
			});
		});
		
		function checkData(){
			$('#params').bootstrapValidator({
			　　　　　message: '输入值错误，请重新输入',
			            　   feedbackIcons:{
			                　　　　　　　　valid: 'glyphicon glyphicon-ok',
			                　　　　　　　　invalid: 'glyphicon glyphicon-remove',
			                　　　　　　　　validating: 'glyphicon glyphicon-refresh'
			            　　　　　　　　   },
			            fields: {
			            	empName : {
			                    message: '用户名验证失败',
			                    validators: {
			                        notEmpty: {
			                            message: '用户名不能为空'
			                        },
			                        stringLength: {
			                            min: 1,
			                            max: 18,
			                            message: '用户名长度必须在1到18位之间'
			                        },
			                        regexp: {
			                            regexp: /^[a-zA-Z0-9_]+|[\u4e00-\u9fa5]+$/,
			                            message: '用户名只能包含大写、小写、数字和下划线'
			                        }
			                    }
			                }
			            }
			        });
		}
		
		function initData(){
			$.ajax({
				type : "get",
				url : "/HMS/queryAllDeptName",
				dataType : 'json',
				data : {},
				contentType : "application/json;charset=UTF-8",
				success : function(val) {
					data = val.obj;
					console.log(data);
					for(var i=0;i<data.length;i++){
						$("#departName").append("<option>"+data[i]+"</option>");
					}
					
				},
				error : function(data) {
					alert('连接失败');
				}
			});
		}
	</script>
</body>

</html>
